package com.qfedu.yige.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.qfedu.yige.common.Result;
import com.qfedu.yige.pojo.PowerUser;

import com.qfedu.yige.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/user")
public class UserController {

    @Autowired
    private UserService userService ;

    @Autowired
    private PasswordEncoder passwordEncoder;

    @PostMapping("/insert")
    public Result insertUser(@RequestBody PowerUser poweruser){

        poweruser.setSid(0);
        String password = poweruser.getPassword();
        String encode = passwordEncoder.encode(password);
        poweruser.setPassword(encode);

        boolean save = userService.save(poweruser);
        if (save){
            Result result = new Result(true, null, null);

            return result;
        }

        return  new Result(false,null,null);
    }

    //实名认证
    //{userId:1,realName:"张三",identificationNumber:"3623*******"}
    @PostMapping("/realNameAuthentication")
    public Result realNameAuthentication(PowerUser poweruser) {
        return userService.realNameAuthentication(poweruser);
    }


}
